// pages/index/service/service.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
    tabList:[
      { id: 0,  item:"综合排序" },
      { id: 1, item:"距离优先"},
    ],
    page:"1",
    sort:'mix',
    appoList:[],
    lat:'',
    long:'',
    cate:''
  },

  jump(e) {
    let id = e.currentTarget.dataset.iindex,  //图片的索引
      index = e.currentTarget.dataset.lindex; //列表的索引
    wx.previewImage({
      current: this.data.appoList[index].pic[id],
      urls: this.data.appoList[index].pic
    })
  },
  video(e) {
    let index = e.currentTarget.dataset.index;
    let video = this.data.appoList[index].video;

    wx.navigateTo({
      url: '../video/video?video=' + video,
    })
  },
  onLoad: function (options) {
      let self=this;
      let cate=options.cate,
        lat = options.lat,
        long = options.long;
        self.setData({
          lat:lat,
          long:long,
          cate: cate
        })
        self.ajax();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  ajax(){
    let self=this;
    app.util.ajax(
      {
        url: 'api/Appointment/getCatList',
        method: 'POST',
        data: {
          cate: self.data.cate,
          latitude: self.data.lat,
          longitude: self.data.long,
          page: self.data.page,
          sort: self.data.sort
        },
      }, res => {
        self.setData({
          appoList: res.data.data
        })

      }
    )
  },
  clickTab(e){
    let self=this;
    let index = e.currentTarget.dataset.current;
    self.setData({
      currentTab: index
    }) 
    if(index==0)
    {
      self.setData({
        sort:"mix"
      })
      self.ajax()
    }else if(index==1){
      self.setData({
        sort: "distance"
      })
      self.ajax()
    }
   
  }
 
})